<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件修饰</title>
    <script src="./js/vue.js"></script>
    <style>
        .cc {
            width: 200px;
            height: 200px;
            border: 5px solid burlywood;
            background-color: aqua;
        }

        .ccColor {
            background-color: blueviolet;
        }

        .cc_div {
            width: 50px;
            height: 50px;
            border: 5px solid;
            background-color: blue;
            margin: 70px auto;
        }

        .ccDivColor {
            background-color: #00ff00;
        }
    </style>
</head>

<body>
    <div id="app">
        {{msg}}

        <div class="cc" :class="{ccColor:isShowColor}" @click="changeColor">
            <!-- stop阻止事件冒泡 -->
            <div class="cc_div" :class="{ccDivColor:isShowSmallColor}" @click.stop="changeSmallColor"></div>
        </div>

        <!-- prevent阻止标签的默认事件 -->
        <a href="https://www.baidu.com" @click.prevent="aclick">点击跳转</a>

        <!-- 只触发标签自身的事件 -->
        <div class="cc" @click.self="divClick">
            <!-- stop阻止事件冒泡 -->
            <input type="button" value="按钮1" @click.stop="btnClick1" />
            <input type="button" value="按钮2" @click.stop="btnClick2" />
        </div>


        <!-- once一次作用：就是让指定事件只触发一次 -->
        <a href="https://www.baidu.com" @click.prevent.once="aclick">点进</a>
    </div>
</body>

</html>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            msg: 'hello world',
            isShowColor: false,
            isShowSmallColor: false
        },
        methods: {
            changeColor() {
                this.isShowColor = !this.isShowColor
            },
            changeSmallColor() {
                this.isShowSmallColor = !this.isShowSmallColor
            },
            aclick() {
                alert('点击了a标签')
            },
            divClick() {
                alert('点击了父类')
            },
            btnClick1() {
                alert('点击了按钮1')
            },
            btnClick2() {
                alert('点击了按钮2')
            }
        },
        computed: {

        },
    })
</script>